<template>
  <div>
    <div
      style="width: 20%; float: left"
      v-loading.fullscreen.lock="fullscreenLoading"
    >
      <el-card shadow="never">
        <el-row :gutter="30">
          <el-col :span="7">
            <span>请输入分单号</span>
          </el-col>

          <el-col :span="6">
            <el-button
              size="mini"
              type="warning"
              @click="uploadShow"
              style="margin-left: 10px"
              >导入分单</el-button
            >
          </el-col>
          <el-col :span="6" class="right">
            <el-button
              size="mini"
              type="success"
              @click="searchSingleMergeWaybill"
              style="margin-left: 10px"
              >确认</el-button
            >
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-form>
          <el-form-item
            label="分单号："
            label-width="70px"
            style="height: 450px"
          >
            <el-input
              type="textarea"
              :rows="15"
              placeholder="请输入分单号，换行隔开"
              :change="checkWaybillNo()"
              v-model="waybillNos"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <div style="width: 80%; float: right; height: 600px">
      <el-card>
        <el-row :gutter="50">
          <el-col :span="8">
            <span>详细信息>>{{ waybillNo }}</span>
          </el-col>
          <el-col :span="16">
            <el-button-group>
              <!-- <el-button
                size="mini"
                type="success"
                @click="generateWaybillSingleNo('BG')"
                >生成报关分单号</el-button
              >
              <el-button
                size="mini"
                type="success"
                @click="generateWaybillSingleNo('QG')"
                >生成清关分单号</el-button
              > -->
              <el-button size="mini" type="success" @click="cancelHAWB"
                >取消分单</el-button
              >
              <el-button
                size="mini"
                type="success"
                @click="batchWaybillSingleNo"
                >生成分单</el-button
              >
              <el-button size="mini" type="success" @click="logisticsShow"
                >保存</el-button
              >
              <el-button size="mini" type="success" @click="batchDeleteWaybill"
                >批量删除</el-button
              >
            </el-button-group>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="1">
            <span>&nbsp;</span>
          </el-col>
          <el-col :span="22">
            <el-table
              :row-style="{ height: '10px' }"
              :cell-style="{ padding: '0px' }"
              :data="seaAirWaybillForm"
              border
              :summary-method="getSummaries"
              show-summary
              height="280"
              style="width: 100%; font-size: 10px"
              ref="waybillTable"
            >
              <el-table-column
                type="selection"
                align="center"
              ></el-table-column>
              <el-table-column prop="waybillNo" label="运单号" sortable>
              </el-table-column>
              <el-table-column prop="waybillSingleNo" label="分单号" sortable width="150">
                <template slot-scope="scope">
                  <el-input
                    size="mini"
                    clearable
                    v-model="scope.row.waybillSingleNo"
                  ></el-input>
                </template>
              </el-table-column>
              <!-- <el-table-column prop="inStockActualWeight" label="实重">
              </el-table-column>
              <el-table-column prop="inStockVolume" label="体积">
              </el-table-column>
              <el-table-column prop="inStockChargedWeight" label="计费重">
              </el-table-column>
              <el-table-column prop="inStockTotalPackages" label="件数">
              </el-table-column> -->
              <el-table-column label="客户简称" sortable show-overflow-tooltip>
                <template slot-scope="scope">
                  <span>{{ customerMap[scope.row.customerId] }}</span>
                </template>
              </el-table-column>
              <el-table-column label="入库渠道" sortable show-overflow-tooltip>
                <template slot-scope="scope">
                  <span>{{
                    customerChannelMap[scope.row.inStockChannel]
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="importerCompanyName"
                label="进口商"
                sortable
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="vat"
                label="VAT"
                sortable
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column label="是否报关" sortable>
                <template slot-scope="scope">
                  <span>{{ yesNos[scope.row.isCustomerDeclaration] }}</span>
                </template>
              </el-table-column>
              <el-table-column label="国家" sortable show-overflow-tooltip>
                <template slot-scope="scope">
                  <span>{{ countryMap[scope.row.countryId] }}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="dispatchAddressCode"
                label="仓库代码"
                sortable
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column label="状态" sortable>
                <template slot-scope="scope">
                  <span>{{ m(statusMap[scope.row.status]) }}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="mergerDeclarationNo"
                label="合并报关号"
                sortable
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <i
                    class="el-icon-close"
                    @click="delWaybill(scope.$index, scope.row)"
                  ></i>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
          <el-col :span="1">
            <span>&nbsp;</span>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-form>
          <el-row>
            <el-col :span="10">
              <el-form-item label="备注：" label-width="100px" style="">
                <el-input
                  type="textarea"
                  :rows="7"
                  placeholder="请输入备注"
                  v-model="customerRemark"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <span>&nbsp;</span>
            </el-col>
            <el-col :span="10">
              <el-row>
                <el-col :span="18">
                  <el-form-item label="目的港：" label-width="100px" style="">
                    <el-select
                      v-model="portId"
                      placeholder="请选择目的港"
                      clearable
                      :style="{ width: '100%' }"
                      filterable
                    >
                      <el-option
                        v-for="(k, v) in configPortMap"
                        :key="v"
                        :label="configPortMap[v]"
                        :value="parseInt(v)"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="18">
                  <el-form-item
                    label="清关服务商："
                    label-width="100px"
                    style=""
                  >
                    <el-select
                      v-model="customsClearanceAgent"
                      placeholder="请选择清关服务商"
                      clearable
                      :style="{ width: '100%' }"
                      filterable
                    >
                      <el-option
                        v-for="(k, v) in serviceCompanyOptions"
                        :key="v"
                        :label="serviceCompanyOptions[v]"
                        :value="parseInt(v)"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="18">
                  <el-form-item label="服务商：" label-width="100px" style="">
                    <el-select
                      v-model="serviceId"
                      placeholder="请选择服务商"
                      clearable
                      :style="{ width: '100%' }"
                      filterable
                    >
                      <el-option
                        v-for="(k, v) in serviceCompanyOptions"
                        :key="v"
                        :label="serviceCompanyOptions[v]"
                        :value="parseInt(v)"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <!-- <div  class="minheight" :class="{ maxheight: flag }"> -->

      <el-dialog
        title="选择物流方式"
        :visible.sync="logistics"
        :modal="false"
        width="30%"
      >
        <template v-slot:title>
          <span>选择物流方式</span>
          <el-select style="margin-left: 20px;" v-model="mergeNumber" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <el-row>
          <el-col :span="8">
            <el-button
              round
              :disabled="disabled"
              @click="saveSeaAirMerge('FCL')"
              >FCL</el-button
            >
          </el-col>
          <el-col :span="8">
            <el-button
              round
              :disabled="disabled"
              @click="saveSeaAirMergeByLcl('LCL')"
              >LCL</el-button
            >
          </el-col>
          <el-col :span="8">
            <el-button
              round
              :disabled="disabled2"
              @click="saveSeaAirMerge('AIR')"
              >AIR</el-button
            >
          </el-col>
        </el-row>
      </el-dialog>

      <el-dialog
        title="导入方式创建分单"
        :visible.sync="upload"
        :modal="false"
        width="40%"
      >
        <el-upload
          class="upload-demo"
          drag
          action="fakeaction"
          :http-request="uploadFn"
          multiple
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">
            只能上传EXCEL文件，且不超过10Mb
          </div>
        </el-upload>
      </el-dialog>

      <!-- </div> -->
    </div>
  </div>
</template>
<script>
import axios from "axios";
import { ajax } from "@/store/yg/common/utils";
import * as constant from "@/store/yg/common/constant";
import { untransform } from "@/store/yg/common/uri";
import { m } from "@/store/yg/common/local";
import { clone } from "@/utils/clone";
export default {
  props: {
    waybillId: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      book: {},
      dialogVisible: false,
      disabled: false,
      disabled2: false,
      configPortMap: {},
      customsClearanceAgent: "",
      serviceId: "",
      yesNos: {
        1: "是",
        0: "否"
      },
      portId: "",
      customerMap: {},
      serviceCompanyOptions: {},
      customerChannelMap: {},
      countryMap: {},
      statusMap: {},
      waybillNo: "",
      status: null,
      fullscreenLoading: false,
      customerRemark: "",
      action: "",
      feeData: [],
      fileList: [
        { name: "food.jpeg", url: "" },
        { name: "food2.jpeg", url: "" }
      ],
      flag: true,
      //用来统计 编辑创建合单时 删除的合单
      delWaybillIds: [],

      seaAirWaybillForm: [
        // {
        // waybillNo:"",
        // waybillSingleNo:"",//用来暂时展示分单号
        // shippingWay:"",
        // inStockActualWeight:"",
        // inStockVolume:"",
        // inStockChargedWeight:"",
        // inStockTotalPackages:"",
        // serviceVolume:"", //下面用于接收合单总和
        // serviceActualWeight:"",
        // serviceVolumeWeight:"",
        // serviceTotalPackages:"",
        // packingLists:[]  //用来暂时存放运单信息
        // },
      ],
      sum: {
        inStockActualWeight: "",
        inStockVolume: "",
        inStockChargedWeight: "",
        inStockTotalPackages: ""
      },
      columns: [],
      waybillNos: "",
      waybill_zxhwck_file: "",
      logistics: false,
      upload: false,
      options: [{
        value: 1,
        label: '1'
      }, {
        value: 2,
        label: '2'
      }, {
        value: 3,
        label: '3'
      }, {
        value: 4,
        label: '4'
      }, {
        value: 5,
        label: '5'
      },{
        value: 6,
        label: '6'
      },{
        value: 7,
        label: '7'
      },{
        value: 8,
        label: '8'
      },{
        value: 9,
        label: '9'
      },{
        value: 10,
        label: '10'
      }],
      mergeNumber: 1
    };
  },
  watch: {},
  beforecreate() {
    this.waybillNo = "";
    this.seaAirWaybillForm = [];
  },
  mounted() {
    console.log("xxxxxxxxxx11111", this.waybillId);
    // if (this.waybillId != null) {
    this.loadWaybillMergeNew();
    // } else {
    //   //this.searchSingleMergeWaybill();
    // }
  },
  created: function() {
    this.action =
      constant.API_SERVER +
      "/api/consume/upload?uri=" +
      untransform(this.$route.params.uri) +
      "&f=importSeaAirMerge&type=edit&name=sub";
    if (this.waybillId) {
      this.action = this.action + "&id=" + this.waybillId;
    }

    console.log("this.action", this.action);
  },
  methods: {
    m(k) {
      return m(k);
    },
    checkWaybillNo() {
      //自动过滤中文等字符，只留下英文+数字
      this.waybillNos = this.waybillNos.replace(/[^\n\r\a-\z\A-\Z0-9]/g, "");
    },
    //删除分单
    delWaybill(index, row) {
      console.log("row", row);
      // if (this.status >= 90) {
      //   this.$message.error("合单状态≥已离港的订单不能删除");
      //   return;
      // }
      let waybillIdArr = [];
      waybillIdArr.push(row.id);
      var params = {};
      params["ids"] = waybillIdArr;
      params["waybillId"] = this.waybillId;
      this.fullscreenLoading = true;
      this.$confirm("确认要删除吗？").then(_ => {
        ajax("updateWaybillMergeId", params).then(
          res => {
            console.log(res);
            if (res.code === 200) {
              this.$message.success("操作成功");
              // location.reload();
              this.seaAirWaybillForm.splice(index, 1);
              //  this.delWaybillIds.push(row.id);
            } else {
              this.fullscreenLoading = false;
              this.$message.error(res.message);
            }
            this.fullscreenLoading = false;
          },
          error => {
            console.log(error);
            this.fullscreenLoading = false;
          }
        );
      });
      this.fullscreenLoading = false;
    },

    loadWaybillMergeNew() {
      this.fullscreenLoading = true;
      var params = {};
      params["id"] = this.waybillId;
      ajax("loadWaybillMergeNew", params).then(
        res => {
          this.fullscreenLoading = false;
          if (res.code == 200) {
            if (res.data["simpleWaybillMerge"]) {
              this.waybillNo = res.data["simpleWaybillMerge"]["waybillNo"];
              this.status = res.data["simpleWaybillMerge"]["status"];
            }
            var singleData = res.data["simpleWaybillQuerySingles"];
            this.serviceCompanyOptions = res.data["serviceCompanyOptions"];
            this.configPortMap = res.data["configPortMap"];
            this.customerMap = res.data["customerMap"];
            this.customerChannelMap = res.data["customerChannelMap"];
            this.countryMap = res.data["countryMap"];
            this.statusMap = res.data["statusMap"];

            console.info("this.statusMap", this.statusMap);
            this.seaAirWaybillForm = [];
            if (null != singleData) {
              singleData.forEach(element => {
                this.seaAirWaybillForm.push(element);
              });
            }
          }
        },
        error => {
          console.log(error);
        }
      );
    },

    driversWaybillNo() {
      this.pickUpForm.id = this.$store.state.edit.row["id"];
      this.pickUpForm.waybillIds = this.$store.state.edit.ids;
      ajax("driversWaybillNo", this.pickUpForm).then(
        res => {
          console.log(res);
          this.pickUpForm.waybillNo = res.waybillNo;
        },
        error => {
          console.log(error);
        }
      );
    },
    searchSingleMergeWaybill() {
      //查询输入的分单号
      var params = {};
      if (this.waybillNos && null != this.waybillNos && "" != this.waybillNos) {
        var waybillNum = this.waybillNos.trim();
        var texta = waybillNum.split("\n");
        params["param6"] = texta;
        this.fullscreenLoading = true;
        ajax("searchSingleMergeWaybill", params).then(
          res => {
            this.fullscreenLoading = false;
            console.log(res);
            if (res.code != 200) {
              this.$message.error(res.message);
            } else {
              for (const waybills of res.data) {
                const waybillFlag = false;
                for (const waybillForm of this.seaAirWaybillForm) {
                  if (waybills.waybillNo === waybillForm.waybillNo) {
                    waybillForm.waybillSingleNo = waybills.waybillSingleNo;
                    waybillFlag = true;
                    break;
                  }
                }
                //如果table中存在该运单的话不进行添加
                if (!waybillFlag) {
                  this.seaAirWaybillForm.push(waybills);
                } // else {
                // this.$message.error("分单已存在该合单，无需重复添加");
                // }
              }
            }
          },
          error => {
            console.log(error);
          }
        );
      } else {
        this.$message.error("请输入分单号");
        return;
      }
    },
    uploadFn(params) {
      //自定义上传文件
      const file = params.file,
        fileType = file.type,
        isImage = fileType.indexOf("pdf") !== -1,
        isLt4M = file.size / 1024 / 1024 < 4;

      // 根据后台需求数据格式
      const form = new FormData();
      // 文件对象
      form.append("items[]", file);
      this.fullscreenLoading = true;
      axios({
        method: "post",
        url: this.action,
        data: form
      })
        .then(response => {
          if (response.data.code != 200) {
            this.$notify.error({
              title: "错误",
              message: "上传失败!" + response.data.message
            });
          } else {
            this.seaAirWaybillForm = response.data.data["success"];
            this.book = response.data.data["book"];
            console.log("response.data>>>", response.data.data["filePath"]);
            this.waybill_zxhwck_file = response.data.data["filePath"];
            console.log("aaaa", this.seaAirWaybillForm);
            this.upload = false;
          }
          this.fullscreenLoading = false;
        })
        .catch(error => {
          console.log(error);
          this.$notify.error({
            title: "错误",
            message: "上传失败!"
          });
          this.fullscreenLoading = false;
        });
    },

    uploadShow() {
      this.upload = true;
    },
    logisticsShow() {
      //console.log("合单号===" + this.waybillNo);

      // if (this.status != null && this.status >= 80) {
      //   this.$message.error("合单状态≥已报关放行，不能生成分单");
      //   return;
      // }
      var aeWaybillNo = this.waybillNo; //合单号
      if (aeWaybillNo != "") {
        if (
          this.waybillNo.indexOf("ZX") != -1 ||
          this.waybillNo.indexOf("AIR") != -1 ||
          this.waybillNo.indexOf("AE") != -1
        ) {
          this.disabled = true;
        }

        if (
          this.waybillNo.indexOf("FCL") != -1 ||
          this.waybillNo.indexOf("LCL") != -1
        ) {
          this.disabled2 = true;
        }
      } else {
        //取table里面的分单号
        var waybillSingleNos = "";
        this.seaAirWaybillForm.forEach(element => {
          if (null != element.waybillNo && element.waybillNo != "") {
            waybillSingleNos = element.waybillNo;
            return;
          }
        });
        // console.log("分单号===" + waybillSingleNos);
        if (
          waybillSingleNos.indexOf("ZX") != -1 ||
          waybillSingleNos.indexOf("AIR") != -1
        ) {
          this.disabled = true;
        }

        if (
          waybillSingleNos.indexOf("FCL") != -1 ||
          waybillSingleNos.indexOf("LCL") != -1
        ) {
          this.disabled2 = true;
        }
      }

      this.logistics = true;
    },

    //取消分单
    cancelHAWB() {
      let waybillSelect = this.$refs.waybillTable.selection; //获取选中的行
      // if (this.status != null && this.status >= 80) {
      //   this.$message.error("合单状态≥已报关放行，不能取消分单");
      //   return;
      // }
      if (waybillSelect.length === 0) {
        this.$message.error("请选择要取消的分单");
        return;
      }

      let waybillIdArr = [];
      waybillSelect.forEach(element => {
        waybillIdArr.push(element.id);
      });
      //console.log("waybillIdArr", waybillIdArr);
      this.fullscreenLoading = true;
      var params = {};
      params["ids"] = waybillIdArr;
      ajax("cancelHAWB", params)
        .then(res => {
          this.fullscreenLoading = false;
          console.log(res);
          if (res.code === 200) {
            this.$refs.waybillTable.clearSelection();
            this.$message.success("操作成功");
            // location.reload();
            if (this.waybillNos) {
              this.searchSingleMergeWaybill();
            } else {
              this.loadWaybillMergeNew();
            }
          } else {
            this.$message.error(res.message);
          }
        })
        .catch(error => {
          this.fullscreenLoading = false;
          console.log(error);
        });
    },
    //生成分单
    batchWaybillSingleNo() {
      let waybillSelect = this.$refs.waybillTable.selection; //获取选中的行

      // if (this.status != null && this.status >= 80) {
      //   this.$message.error("合单状态≥已报关放行，不能生成分单");
      //   return;
      // }

      if (waybillSelect.length === 0) {
        this.$message.error("请选择要生成的分单");
        return;
      }

      this.fullscreenLoading = true;
      let waybillIdArr = [];
      waybillSelect.forEach(element => {
        waybillIdArr.push(element.id);
      });
      //console.log("waybillIdArr", waybillIdArr);
      var params = {};
      params["ids"] = waybillIdArr;
      ajax("batchWaybillSingleNo", params).then(
        res => {
          this.fullscreenLoading = false;
          console.log(res);
          if (res.code === 200) {
            this.$refs.waybillTable.clearSelection();
            this.$message.success("操作成功");
            // location.reload();
            if (this.waybillNos) {
              this.searchSingleMergeWaybill();
            } else {
              this.loadWaybillMergeNew();
            }
          } else {
            this.$message.error(res.message);
          }
        },
        error => {
          console.log(error);
        }
      );
    },

    saveSeaAirMergeByLcl(shippingWay) {
      this.$confirm("是否需要拼装成FCL？取消不拼装继续保存？").then(_ => {
        this.saveSeaAirMerge("LCL");
      });
    },
    //生成报关分单号；生成清关分单号
    generateWaybillSingleNo(operation) {
      if (this.status != null && this.status >= 90) {
        this.$message.error("合单状态≥已离港的订单不能修改");
        return;
      }
      const table = clone(this.seaAirWaybillForm);
      console.log("table>>>=", table);
      if (table.length === 0) {
        this.$message.error("没有运单信息不能生成");
        return;
      }
      // var mergeNum = this.mergeNumber;
      // if(table.length>0 && mergeNum !=1){
      //   this.$message.error("运单只能参与一个合单");
      //   return;
      // }
      this.fullscreenLoading = true;
      const ids = [];
      for (const i of table) {
        ids.push(i.id);
      }

      var params = {};
      params["ids"] = ids;
      params["param1"] = operation;

      ajax("generateWaybillSingleNo", params).then(
        res => {
          this.fullscreenLoading = false;
          if (res.code === 200) {
            this.$message.success("操作成功");
            if (this.waybillNos) {
              this.searchSingleMergeWaybill();
            } else {
              this.loadWaybillMergeNew();
            }
          } else {
            this.$message.error(res.message);
          }
        },
        error => {
          console.log(error);
        }
      );
    },

    saveSeaAirMerge(shippingWay) {
      // if (this.status != null && this.status >= 90) {
      //   this.$message.error("合单状态≥已离港的订单不能修改");
      //   return;
      // }

      // if (this.seaAirWaybillForm.length === 0) {
      //   this.$message.error("无运单信息，无需保存");
      //   return;
      // }

      //保存合单信息
      this.logistics = false;
      //下面用于接收合单总和
      var params = {};
      // params["totalInStockActualWeight"] = this.sum.inStockActualWeight;
      // params["totalInStockVolume"] = this.sum.inStockVolume;
      // params["totalInStockChargedWeight"] = this.sum.inStockChargedWeight;
      // params["totalInStockTotalPackages"] = this.sum.inStockTotalPackages;
      params["id"] = this.waybillId;
      params["customerRemark"] = this.customerRemark;
      params["shippingWay"] = shippingWay;
      var waybillNos = [];
      var waybillNoSingleRelationShipMap = {};
      var shippingWays = [];
      this.seaAirWaybillForm.forEach(element => {
        if (null != element.waybillNo && element.waybillNo != "") {
          waybillNos.push(element.waybillNo);
        }
        shippingWays.push(element.shippingWay);
        if (element.shippingWay == "99") {
          this.$message.error(
            "快递单号:" + element.waybillNo + "不允许参加合单"
          );
          return;
        }
        waybillNoSingleRelationShipMap[element.waybillNo] =
          element.waybillSingleNo;
      });
      if (
        shippingWays.length > 1 &&
        shippingWays.indexOf("ZX") > -1 &&
        (shippingWays.indexOf("LCL") > -1 || shippingWays.indexOf("FCL") > -1)
      ) {
        this.$message.error(
          "运单组合不正确,【AIR，ZX】/【FCL，LCL】可以合单，其他只能渠道一样的合单"
        );
        return;
      }
      var mergeNum = this.mergeNumber;
      console.log(mergeNum)
      if(
        shippingWays.length > 0 && mergeNum != 1
      ){
        this.$message.error(
          "运单只能参与一个合单"
        );
        return;
      }
      if (
        shippingWays.length > 1 &&
        shippingWays.indexOf("AIR") > -1 &&
        (shippingWays.indexOf("LCL") > -1 || shippingWays.indexOf("FCL") > -1)
      ) {
        this.$message.error(
          "运单组合不正确,【AIR，ZX】/【FCL，LCL】可以合单，其他只能渠道一样的合单"
        );
        return;
      }
      params["waybillNos"] = waybillNos;
      // params["delWaybillIds"] = this.delWaybillIds;
      console.log(
        "waybillNoSingleRelationShipMap>>",
        waybillNoSingleRelationShipMap
      );
      params["waybillNoSingleRelationShipMap"] = waybillNoSingleRelationShipMap;
      params["filePath"] = this.waybill_zxhwck_file;
      params["bookInfo"] = this.book;
      this.fullscreenLoading = true;
      var resCode=0;
      for (var i=0;i<mergeNum;i++){
        ajax("saveSeaAirMerge", params).then(
          res => {
            this.fullscreenLoading = false;
            resCode=res.code;
            if (res.code === 200) {
              this.$message.success("保存成功");
              location.reload();
            } else {
              this.$message.error(res.message);
            }
          },
          error => {
            console.log(error);
          }
        );
      }
      if(resCode===200){
        location.reload();
      }
    },
    //批量删除分单
    batchDeleteWaybill() {
      if (this.status >= 90) {
        this.$message.error("合单状态≥已离港的订单不能删除");
        return;
      }
      let waybillSelect = this.$refs.waybillTable.selection; //获取选中的行
      // if (this.status != null && this.status >= 80) {
      //   this.$message.error("合单状态≥已报关放行，不能取消分单");
      //   return;
      // }
      if (waybillSelect.length === 0) {
        this.$message.error("请选择要删除的分单");
        return;
      }

      let waybillIdArr = [];
      waybillSelect.forEach(element => {
        waybillIdArr.push(element.id);
      });
      //console.log("waybillIdArr", waybillIdArr);
      this.fullscreenLoading = true;
      var params = {};
      params["ids"] = waybillIdArr;
      params["waybillId"] = this.waybillId;
      this.$confirm("确定要删除吗？").then(_ => {
        ajax("updateWaybillMergeId", params)
          .then(res => {
            this.fullscreenLoading = false;
            console.log(res);
            if (res.code === 200) {
              this.$refs.waybillTable.clearSelection();
              this.$message.success("操作成功");
              // location.reload();
              if (this.waybillNos) {
                this.searchSingleMergeWaybill();
              } else {
                this.loadWaybillMergeNew();
              }
            } else {
              this.$message.error(res.message);
            }
          })
          .catch(error => {
            this.fullscreenLoading = false;
            console.log(error);
          });
      });
      this.fullscreenLoading = false;
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return (prev * 1000 + curr * 1000) / 1000;
            } else {
              return prev;
            }
          }, 0);
          // sums[index] += ' KG';
        } else {
          sums[index] = "";
        }
      });
      console.log(sums);
      this.sum.inStockActualWeight = sums[2];
      this.sum.inStockVolume = sums[3];
      this.sum.inStockChargedWeight = sums[4];
      this.sum.inStockTotalPackages = sums[5];
      console.log(this.sum);
      return sums;
    }
  }
};
</script>
<style lang="scss" scoped>
.row-item {
  color: #3f4652;
  line-height: 28px;
  margin-bottom: 14px;
}

.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409eff;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}

.el-card {
  margin-top: 10px;
  margin-bottom: 20px;
  margin-left: 20px;
  margin-right: 20px;
}

.maxheight {
  display: none;
}
</style>
